package com.finer.service.impl;

import com.finer.entity.buy.FinerBuyBackOrderDetail;
import com.finer.dao.FinerBuyBackOrderDetailDao;
import com.finer.service.FinerBuyBackOrderDetailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 采购退货订单详情表(FinerBuyBackOrderDetail)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:36
 */
@Service("finerBuyBackOrderDetailService")
public class FinerBuyBackOrderDetailServiceImpl implements FinerBuyBackOrderDetailService {
    @Resource
    private FinerBuyBackOrderDetailDao finerBuyBackOrderDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FinerBuyBackOrderDetail queryById(Integer id) {
        return this.finerBuyBackOrderDetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param finerBuyBackOrderDetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerBuyBackOrderDetail> queryByPage(FinerBuyBackOrderDetail finerBuyBackOrderDetail, PageRequest pageRequest) {
        long total = this.finerBuyBackOrderDetailDao.count(finerBuyBackOrderDetail);
        return new PageImpl<>(this.finerBuyBackOrderDetailDao.queryAllByLimit(finerBuyBackOrderDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerBuyBackOrderDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerBuyBackOrderDetail insert(FinerBuyBackOrderDetail finerBuyBackOrderDetail) {
        this.finerBuyBackOrderDetailDao.insert(finerBuyBackOrderDetail);
        return finerBuyBackOrderDetail;
    }

    /**
     * 修改数据
     *
     * @param finerBuyBackOrderDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerBuyBackOrderDetail update(FinerBuyBackOrderDetail finerBuyBackOrderDetail) {
        this.finerBuyBackOrderDetailDao.update(finerBuyBackOrderDetail);
        return this.queryById(finerBuyBackOrderDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.finerBuyBackOrderDetailDao.deleteById(id) > 0;
    }
}
